home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / The Hacks / MACtive Desktop / Source / Sources / AppleEvent.cc next >
Encoding:
C/C++ Source or Header  |  1997-07-30  |  1.6 KB  |  91 lines  |  [TEXT/CWIE]

  1. #include "FileMenu.h"
  2. #include "AppleEvent.h"
  3.  
  4.  
  5.  
  6.  
  7.  
  8. extern Boolean            gExitFlag;
  9. extern FileMenu            *gFileMenu;
  10.  
  11.  
  12.  
  13.  
  14.  
  15. void InitializeAppleEvents(void)
  16. {
  17.     AEEventHandlerUPP    AECoreProc;
  18.     
  19.     
  20.     /* install the core AppleEvent handlers */
  21.     AECoreProc = NewAEEventHandlerProc(AECoreHandler);
  22.     AEInstallEventHandler(kCoreEventClass,kAEOpenApplication,AECoreProc,kAEOpenApplication,false);
  23.     AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,AECoreProc,kAEOpenDocuments,false);
  24.     AEInstallEventHandler(kCoreEventClass,kAEPrintDocuments,AECoreProc,kAEPrintDocuments,false);
  25.     AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,AECoreProc,kAEQuitApplication,false);
  26. }
  27.  
  28.  
  29.  
  30.  
  31.  
  32. void ProcessAppleEvent(EventRecord *event)
  33. {
  34.     AEProcessAppleEvent(event);
  35. }
  36.  
  37.  
  38.  
  39.  
  40.  
  41. pascal SInt16 AECoreHandler(AppleEvent *aevent,AppleEvent *areply,long refcon)
  42. {
  43.     /* use refcon to dispatch event */
  44.     switch(refcon)
  45.     {
  46.         case kAEOpenApplication:
  47.             break;
  48.         
  49.         case kAEOpenDocuments:
  50.             break;
  51.         
  52.         case kAEPrintDocuments:
  53.             break;
  54.         
  55.         case kAEQuitApplication:
  56.             gExitFlag = true;
  57.             break;
  58.     }
  59.     
  60.     /* make sure event was properly handled */
  61.     return (SInt16)AEGotRequiredParams(aevent);
  62. }
  63.  
  64.  
  65.  
  66.  
  67.  
  68. SInt32 AEGotRequiredParams(AppleEvent *aevent)
  69. {
  70.     DescType    returnedType;
  71.     Size        actualSize;
  72.     SInt32    err;
  73.     
  74.     
  75.     /* did we extract all the required parameters? */
  76.     err = AEGetAttributePtr(aevent,keyMissedKeywordAttr,typeWildCard,&returnedType,nil,0,&actualSize);
  77.     if (err == errAEDescNotFound)
  78.     {
  79.         /* we got all the required parameters */
  80.         return noErr;
  81.     }
  82.     else if (!err)
  83.     {
  84.         /* we missed a required parameter */
  85.         return errAEEventNotHandled;
  86.     }
  87.     
  88.     /* the call to AEGetAttributePtr failed: weird! */
  89.     return err;
  90. }
  91.